package com.example.sunming.json;

import com.example.sunming.utils.Java8DateUtils;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author: sunming
 * @description
 * @date: 2021/5/19 9:47
 */
public class Demo {
    public static void main(String[] args) {
        Test test = new Test();
        test.setPowerOnSolutionLeft("1000");
        test.setPowerOffSolutionLeft("800");
        test.setPowerOnInkLeft("1000");
        test.setPowerOffInkLeft("500");
        test.setPowerOnTime(Java8DateUtils.parseDateTimeStr("2021-05-19 09:00:00", "yyyy-MM-dd HH:mm:ss"));
        test.setPowerOffTime(Java8DateUtils.parseDateTimeStr("2021-05-19 18:00:00", "yyyy-MM-dd HH:mm:ss"));
        test.setCompMac("fe80::853f:c470:b519:3ada%7");
        List<ExpInkJetSolutionDetail> changeSolution = new ArrayList<>();
        List<ExpInkJetSolutionDetail> changeInk = new ArrayList<>();
        Date date = Java8DateUtils.parseDateTimeStr("2021-05-19 12:00:00", "yyyy-MM-dd HH:mm:ss");
        changeSolution.add(new ExpInkJetSolutionDetail("900", "800", date.getTime()));
        changeInk.add(new ExpInkJetSolutionDetail("900", "500", date.getTime()));
        test.setChangeSolution(changeSolution);
        test.setChangeInk(changeInk);

        JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());

        JSONObject jsonObject = JSONObject.fromObject(test,jsonConfig);
        System.out.println(jsonObject.toString());
    }
}
